package de.lot.model;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.validator.NotNull;

/**
 * A position is part of a StudentLearningOutcome and is related to a trait
 * of the general learning outcome
 *
 * @see LearningOutcome
 * @see Trait
 *
 * @author Stefan Kohler <kohler.stefan@gmail.com>
 */
@Entity
@Table(name = "POSITION")
public class Position implements Serializable {

    private Long id;
    private Result result;
    private Trait trait;
    private StudentLearningOutcome studentLearningOutcome;

    public Position() {
    }

    public Position(Trait trait, StudentLearningOutcome studentLearningOutcome) {
        this.trait = trait;
        this.studentLearningOutcome = studentLearningOutcome;
    }

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    //TODO: Check if @NotNull is needed
    //Removed to be able to save a position w/o predefining a result
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "RESULT_ID")
    public Result getResult() {
        return result;
    }

    public void setResult(Result result) {
        this.result = result;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "TRAIT_ID")
    @NotNull
    public Trait getTrait() {
        return trait;
    }

    public void setTrait(Trait trait) {
        this.trait = trait;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "STUDENTLEARNINGOUTCOME_ID", nullable = false)
    @NotNull
    public StudentLearningOutcome getStudentLearningOutcome() {
        return studentLearningOutcome;
    }

    public void setStudentLearningOutcome(StudentLearningOutcome studentLearningOutcome) {
        this.studentLearningOutcome = studentLearningOutcome;
    }
}
